package com.healthcloud.controller.modules.losewisdom;

import java.util.List;

import com.healthcloud.dto.req.losewisdom.LoseWisdomListReq;
import com.healthcloud.entity.MsgVo;
import com.healthcloud.entity.losewisdom.LoseWisdomScreeningPhqEntity;
import com.healthcloud.service.losewisdom.LoseWisdomScreeningPhqService;
import com.healthcloud.utils.ApiRes;
import com.healthcloud.utils.PageParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 失智PHQ-9筛查表
 * 
 * @author yucl
 * @email yucailong1111@126.com
 * @date 2020-10-26 16:08:18
 */
@Controller
@RequestMapping("/lose/wisdom/screening/phq")
public class LoseWisdomScreeningPhqController {

    private static String prefix = "losewisdom/phq";

    @Autowired
    private LoseWisdomScreeningPhqService phqService;

    @GetMapping("/index")
    public String index() {
        return prefix + "/phq";
    }

    @ApiOperation("跳转至更多页面")
    @GetMapping("/more")
    public String more() {
        return prefix + "/more";
    }

    @ApiOperation("跳转至修改页面")
    @GetMapping("/toUpdate")
    public String toUpdate(@RequestParam("id") Integer id, ModelMap map) {
        LoseWisdomScreeningPhqEntity entity = phqService.queryObject(id);
        map.put("entity", entity);
        return prefix + "/update";
    }


    /**
     * 获取列表信息
     * @param req
     * @param pageParam
     * @return
     */
    @ApiOperation("获取列表信息")
    @PostMapping("/list")
    @ResponseBody
    public MsgVo list(LoseWisdomListReq req, @ModelAttribute("pageParam") PageParam pageParam) {
        List<LoseWisdomScreeningPhqEntity> list = phqService.queryList(req, pageParam);
        int count = phqService.queryTotal(req);
        return new MsgVo(list, count, count, pageParam.getsEcho());
    }

    /**
     * 获取详情
     * @param id
     * @return
     */
    @ApiOperation("获取详情")
    @PostMapping("/detail")
    @ResponseBody
    public ApiRes getById(Integer id) {
        LoseWisdomScreeningPhqEntity entity = phqService.queryObject(id);
        return ApiRes.success(entity);
    }

    /**
     * 新增AD-IE信息
     * @param entity
     * @return
     */
    @ApiOperation("新增AD-IE信息")
    @PostMapping("/save")
    @ResponseBody
    public ApiRes save(LoseWisdomScreeningPhqEntity entity) {
        phqService.save(entity);
        return ApiRes.success();
    }

    /**
     * 修改AD-IE信息
     * @param entity
     * @return
     */
    @ApiOperation("修改AD-IE信息")
    @PostMapping("/update")
    @ResponseBody
    public ApiRes update(LoseWisdomScreeningPhqEntity entity) {
        phqService.update(entity);
        return ApiRes.success();
    }

    /**
     * 删除AD-IE信息
     * @param id
     * @return
     */
    @ApiOperation("删除AD-IE信息")
    @PostMapping("/delete")
    @ResponseBody
    public ApiRes delete(Integer id) {
        phqService.delete(id);
        return ApiRes.success();
    }

}
